package net.minecraft.src;

public class EntitySwampMonster extends EntityWaterThing
{

	public EntitySwampMonster(World world)
	{
		super(world);
		texture = "/pph/mob/Crassigyrinus_Scotticus.png";
		setSize(3F, 0.5F);
	}
	
	public int getMaxHealth()
	{
		return 10;
	}
	
	public void onUpdate()
	{
		super.onUpdate();
		//System.out.println(posX + " " + posY + " " + posZ);
	}
	
	protected void updateWanderPath()
    {
		int newX = MathHelper.floor_double((posX + (double)rand.nextInt(13)) - 6D);
        int newY;
        if(willGoUp)
        {
        	newY = MathHelper.floor_double((posY + (double)rand.nextInt(10)) + 1D); //12 - 16
           	willGoUp = rand.nextInt(100) < 10; //10%
        }
        else
        {
           	newY = MathHelper.floor_double((posY - (double)rand.nextInt(9)) + 2D);
           	willGoUp = rand.nextInt(100) < 100; //50%
        }
        int newZ = MathHelper.floor_double((posZ + (double)rand.nextInt(13)) - 6D);
        setPathToEntity(worldObj.getEntityPathToXYZ(this, newX, newY, newZ, 1F));
    }

	public void updateEntityActionState()
	{
		/*if (1 == 1)
		{
			super.updateEntityActionState();
			return;
		}*/
		if (entityToAttack == null)
		{
			entityToAttack = getClosestEntity(posX, posY, posZ, 5D);
			if (entityToAttack != null)
				setPathToEntity(worldObj.getPathToEntity(this, entityToAttack, 1F));
		}
		else if (entityToAttack.getDistanceSq(posX, posY, posZ) > 10D)
		{
			entityToAttack = null;
		}
		else if (entityToAttack.getDistanceSq(posX, posY, posZ) < 1D)
		{
			if(attackTime == 0)
			{
				//attackEntityFrom(DamageSource.causeMobDamage((EntityLiving)entityToAttack), 2);
				attackTime = 20 + rand.nextInt(5);
			}
			else
				--attackTime;
		}
		
		if (entityToAttack != null)
		{
			/*if (posY > entityToAttack.posY)
			{
				motionY = -0.05F;
				if (posY + motionY < entityToAttack.posY)
					motionY = entityToAttack.posY - posY;
			}
			else
			{
				motionY = 0.05F;
				if (posY + motionY > entityToAttack.posY)
					motionY = entityToAttack.posY - posY;
			}*/
			if (posX > entityToAttack.posX)
			{
				motionX = -0.1F;
				if (posX + motionX < entityToAttack.posX)
					motionX = entityToAttack.posX - posX;
			}
			else
			{
				motionX = 0.1F;
				if (posX + motionX > entityToAttack.posX)
					motionX = entityToAttack.posX - posX;
			}
			if (posZ > entityToAttack.posZ)
			{
				motionZ = -0.1F;
				if (posZ + motionZ < entityToAttack.posZ)
					motionZ = entityToAttack.posZ - posZ;
			}
			else
			{
				motionZ = 0.1F;
				if (posZ + motionZ > entityToAttack.posY)
					motionZ = entityToAttack.posY - posZ;
			}
		}
		super.updateEntityActionState();
	}

	public EntityLiving getClosestEntity(double d, double d1, double d2, double d3)
	{
		double d4 = -1D;
		EntityLiving entityplayer = null;
		for (int i = 0; i < worldObj.playerEntities.size(); i++)
		{
			EntityLiving entityplayer1 = (EntityLiving) worldObj.playerEntities.get(i);
			double d5 = entityplayer1.getDistanceSq(d, d1, d2);
			if ((d3 < 0.0D || d5 < d3 * d3) && (d4 == -1D || d5 < d4))
			{
				d4 = d5;
				entityplayer = entityplayer1;
			}
		}
		if (entityplayer == null)
		{
			for (int i = 0; i < worldObj.loadedEntityList.size(); i++)
			{
				Entity entityplayer1 = (Entity) worldObj.loadedEntityList.get(i);
				if (entityplayer1 instanceof EntityLiving && entityplayer1 instanceof EntitySwampMonster == false)
				{
					double d5 = entityplayer1.getDistanceSq(d, d1, d2);
					if ((d3 < 0.0D || d5 < d3 * d3) && (d4 == -1D || d5 < d4))
					{
						d4 = d5;
						entityplayer = (EntityLiving) entityplayer1;
					}
				}
			}
		}

		return entityplayer;
	}
	
	/* Movement Properties */
	private boolean willGoUp = false;
	private PathEntity pathCopy = null;
	
	/* Animation Properties */
	public int animationFoots = 0;
	public boolean animationFootsUpward = true;
	public int animationTail = 0;
	public boolean animationTailSide = true;
	
	public boolean isMoving()
	{
		return motionX != 0 || motionZ != 0;
	}

}
